package com.cneport.transfer.monitor.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cneport.transfer.monitor.entity.TransportLog;
import com.cneport.transfer.monitor.service.MonitoringViewService;

@Controller
@RequestMapping("/monitoringView")
public class MonitoringViewController {
	
	@Autowired
	private MonitoringViewService monitoringviewservice;
	
    /** LOG 日志操作�? */
    private static final Log log = LogFactory
            .getLog(MonitoringViewController.class);
	
    /**
     * 传输日志列表
     * @param request
     * @param response
     * @return Map
     */
    @RequestMapping(value = "/queryForListByPage", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> queryForListByPage(HttpServletRequest request,
            HttpServletResponse response) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        
        try {
			String messageType = request.getParameter("messageType");
			String senderId =  request.getParameter("senderId");
			String receiverId = request.getParameter("receiverId");
			String startDate = request.getParameter("startDate");
			String endDate = request.getParameter("endDate");
			String transferType = request.getParameter("transferType");
			String transferStat = request.getParameter("transferStat");
			String start = request.getParameter("start");
			String limit = request.getParameter("limit");
			
			
			paramsMap.put("firstIndex", start);
			paramsMap.put("lastIndex", Integer.parseInt(limit)
			        + Integer.parseInt(start) + 1);
			
			paramsMap.put("messageType", messageType);
			paramsMap.put("senderId", senderId);
			paramsMap.put("receiverId", receiverId);
			paramsMap.put("startDate", startDate);
			paramsMap.put("endDate", endDate);
			paramsMap.put("transferType", transferType);
			paramsMap.put("transferStat", transferStat);
			
			List<TransportLog> result= monitoringviewservice.queryMonitoringList(paramsMap);
			
			resultMap.put("root", result);
			resultMap.put("totalProperty", monitoringviewservice.countMonitoring(paramsMap));
			resultMap.put("success", true);
		} catch (Exception e) {
			log.error(e);
			resultMap.put("success", false);
			resultMap.put("msg", "系统异常");
		}
    	
    	return resultMap;
    }
    
    @RequestMapping(value = "/getLogInfo", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getLogInfo(HttpServletRequest request,
            HttpServletResponse response) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        
        try {
			String id = request.getParameter("id");
			paramsMap.put("id", id);
			String message = monitoringviewservice.getLogInfo(paramsMap);
			
			resultMap.put("content", message);
			resultMap.put("success", true);
			resultMap.put("data", "data");
		} catch (Exception e) {
			log.error(e);
			resultMap.put("success", false);
		}
        
       return resultMap;
    }
    
    @RequestMapping(value = "/reSendMessage", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> reSendMessage(HttpServletRequest request,
            HttpServletResponse response) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        
//        try {
//			String id = request.getParameter("id");
//			paramsMap.put("id", id);
//			String message = monitoringviewservice.getLogInfo(paramsMap);
//			
//			resultMap.put("content", message);
//			resultMap.put("success", true);
//			resultMap.put("data", "data");
//		} catch (Exception e) {
//			log.error(e);
//			resultMap.put("success", false);
//		}
        resultMap.put("success", true);
       return resultMap;
    }

}
